package hy.controller;

import hy.beans.Result;
import hy.beans.User;
import hy.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system")
public class SystemCtrl {
    @Autowired
    SystemService service;

    @GetMapping("/user")
    public Result getUser(@RequestParam(required = true,defaultValue = "1",name ="id" ) Integer id){
        System.out.println(id);
        //int i=1/0;测试异常处理
        return service.getUserById(id);
    }
    @PostMapping("/user")
    //前端传入参数如果是json格式字符串，就必须用@RequestBody处理
    public Result addUser(@RequestBody User u){
        return service.addUser(u);
    }

    @PutMapping("/user")
    public Result modifyUser(@RequestBody User u){
        return service.modifyUserById(u);
 }

 @DeleteMapping("/user/{id}")
    public Result deleteUser(@PathVariable Integer id){
        return service.deleteUserById(id);
    }
}